// --------------------------------------------------------------------------------------------------------------------
// <copyright file="MockKinectV2Agent.cs" company="Microsoft Corporation">
// The MIT License (MIT)
// 
// Copyright (c) 2014, Microsoft Corporation
// 
// Permission is hereby granted, free of charge, to any person obtaining a copy
//  of this software and associated documentation files (the "Software"), to deal
//  in the Software without restriction, including without limitation the rights
//  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//  copies of the Software, and to permit persons to whom the Software is
//  furnished to do so, subject to the following conditions:
// 
// The above copyright notice and this permission notice shall be included in
//  all copies or substantial portions of the Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
//  THE SOFTWARE.
// </copyright>
// --------------------------------------------------------------------------------------------------------------------
namespace Test.Robotics.Runtime
{
    using System;
    using System.Runtime.Serialization;
    using System.Threading;
    using Microsoft.Robotics.Runtime;
    using Microsoft.Robotics.Vision.Cameras;
    using Microsoft.Robotics.Vision.Runtime.Cameras;
    using Microsoft.VisualStudio.TestTools.UnitTesting;
    using Test.Robotics.Runtime;

    /// <summary>
    /// Mock kinect v2 agent
    /// </summary>
    public class MockKinectV2Agent : ProducerAgent<DepthCameraAgentMessage<DepthParameters>>,
                                    IMessagePublisher<IRCameraAgentMessage<IRParameters>>,
                                    IMessagePublisher<ColorCameraAgentMessage<ColorParameters>>
    {
        /// <summary>
        /// Forwarder to publish depth message
        /// </summary>
        private IForwarder<IRCameraAgentMessage<IRParameters>> irMessagePublisher;

        /// <summary>
        /// Forwarder to publish depth message
        /// </summary>
        private IForwarder<ColorCameraAgentMessage<ColorParameters>> rgbPublish;

        /// <summary>
        /// Initializes a new instance of the MockKinectV2Agent class.
        /// </summary>
        /// <param name="name">
        /// The name of the agent instance.
        /// </param>
        public MockKinectV2Agent(string name)
            : base(name)
        {
        }

        /// <summary>
        /// Initializer the depth publisher
        /// </summary>
        /// <param name="forwarder">A forwarder that can be used to broadcast our state.</param>
        public void InitializePublisher(IForwarder<IRCameraAgentMessage<IRParameters>> forwarder)
        {
            this.irMessagePublisher = forwarder;
        }

        /// <summary>
        /// Initializer the RGB publisher
        /// </summary>
        /// <param name="forwarder">A forwarder that can be used to broadcast our state.</param>
        public void InitializePublisher(IForwarder<ColorCameraAgentMessage<ColorParameters>> forwarder)
        {
            this.rgbPublish = forwarder;
        }

        /// <summary>
        /// Publishes the IR message
        /// </summary>
        /// <param name="message">The message to publish.</param>
        public void Publish(DepthCameraAgentMessage<DepthParameters> message)
        {
            this.Publisher.Post(message, true);
        }

        /// <summary>
        /// Publishes the depth message
        /// </summary>
        /// <param name="message">The message to publish.</param>
        public void Publish(IRCameraAgentMessage<IRParameters> message)
        {
            this.irMessagePublisher.Post(message, true);
        }

        /// <summary>
        /// Publishes the RGB message
        /// </summary>
        /// <param name="message">The message to publish.</param>
        public void Publish(ColorCameraAgentMessage<ColorParameters> message)
        {
            this.rgbPublish.Post(message, true);
        }
    }
}
